'use strict'

const gohttp =require('gohttp')

const wxkey = require('./wxkey')

//格式化access_token URL
function fmtTokenUrl (appid,secret){
    return `https://api.weixin.qq.com/cgi-bin/token`+`?grant_type=client_credential`+`&appid=${appid}&secret=${secret}`;
}

//开始调用
// ;(async ()=>{
//     let api_url = fmtTokenUrl(wxkey.appid,wxkey.secret);

//     //Promise
//     let ret = await gohttp.get(api_url)
//     .then(res=>{
//         return res.json();
//     });

//     console.log(ret);
// })();

exports.getToken = async function(){
    let api_url = fmtTokenUrl(wxkey.appid,wxkey.secret);

    //Promise
    let ret = await gohttp.get(api_url)
    .then(res=>{
        return res.json();
    });

    return ret;
};